﻿using K8.MDCBB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KingerRobot.MexicoSailunMDC.SpiService;

public class BMesAsrsCuringNormFMes : IMesAsrsCuringNormFMes
{
    public int AddOrUpdateCuringNorm(POMesAsrsCuringNormFMes curingNorm)
    {
        var db = Db.Default;

        var mesCuringNorm = db.MesAsrsCuringNormFMess.Where(t => t.Greentyreno == curingNorm.Greentyreno).FirstOrDefault();

        var result = 0;
        if (mesCuringNorm is null)
        {
            // 添加
            curingNorm.Id = XID.Nextval;
            result = db.MesAsrsCuringNormFMess.Insert(curingNorm);
        }
        else
        {
            // 修改
            result = db.MesAsrsCuringNormFMess.Where(t => t.Greentyreno == curingNorm.Greentyreno).Update(curingNorm);
        }

        return result;
    }

    public int DeleteMesCuringNormByStatus(int status)
    {
        var db = Db.Default;
        var result = db.MesAsrsCuringNormFMess.Where(t => t.Status == status).Delete();
        return result;
    }

    public int UpdateMesCuringNormByStatus(int status)
    {
        var db = Db.Default;
        var fMess = db.MesAsrsCuringNormFMess.ToList();
        foreach (var item in fMess)
        {
            item.Status = status;
        }
        db.MesAsrsCuringNormFMess.UpdateRange(fMess);
        var result = db.SaveChanges();
        return result;
    }
    public POMesAsrsCuringNormFMes GetCuringNormByMaterialCode(string MaterialCode)
    {
        var db = Db.Default;
        var result = db.MesAsrsCuringNormFMess.Where(t => t.Greentyreno == MaterialCode).FirstOrDefault();
        //string s = "";
        return result;
    }

}

